package com.wontube.smr.bo.download;

import java.io.IOException;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wontube.smr.bo.pub.ProxyDownloadListener;




/**
 * @author yuechao
 * 
 */
public class ProxyDownloadServlet extends HttpServlet {
	private static final long serialVersionUID = 5123008877462983237L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String url = req.getParameter("url");
		if (url == null || "".equals(url)) {
			return;
		}
		
		String filename = req.getParameter("filename");
		if (filename == null || "".equals(filename)) {
			return;
		}
		
		AsyncContext ac = req.startAsync();
		ac.setTimeout(24 * 60 * 60 * 1000); // 限一天下载完成
		ac.start(new ProxyDownloadListener(ac, filename, url));
	}
}
